package org.bilinc.gz001.dao;


import org.bilinc.gz001.dao.interfaces.AbstractDaoImpl;
import org.bilinc.gz001.dao.interfaces.IPositionDao;
import org.bilinc.gz001.entity.Position;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

@Component
public class PositionDao extends AbstractDaoImpl<Position> implements IPositionDao {

    private final static String HQL_GET_SIZE = "SELECT COUNT(r) FROM Position r";

    PositionDao() {
    }

    public Long getSize() {
        Long size =  (Long) getSession().createQuery(HQL_GET_SIZE).uniqueResult();
        closeSession();
        return size;
    }

    public Position findByName(String positionName) {
        Position position =  (Position) createCriteriaNoTransaction().add(Restrictions.eq("position", positionName)).uniqueResult();
        closeSession();
        return position;
    }
}
